<template>
  <div class="exhibitor-services">
    <div
      class="page-header"
      :style="bannerImage ? { backgroundImage: `url(${bannerImage})` } : {}"
      :class="{ 'has-bg': !!bannerImage }"
    >
      <div class="container">
        <h1 class="page-title">展商服务</h1>
        <p class="page-subtitle">为参展商提供全方位的服务支持</p>
      </div>
    </div>
    <!-- 导航菜单 -->
    <div class="nav-menu">
      <div class="container">
        <nav class="about-nav">
          <a
            @click="setActiveTab('why-exhibit')"
            :class="['nav-item', { active: activeTab === 'why-exhibit' }]"
          >
            为何参展
          </a>
          <a
            @click="setActiveTab('who-exhibits')"
            :class="['nav-item', { active: activeTab === 'who-exhibits' }]"
          >
            谁来观展
          </a>
          <a
            @click="setActiveTab('exhibit-registration')"
            :class="[
              'nav-item',
              { active: activeTab === 'exhibit-registration' },
            ]"
          >
            参展报名
          </a>
          <!-- <a
            @click="setActiveTab('exhibitor-system')"
            :class="['nav-item', { active: activeTab === 'exhibitor-system' }]"
          >
            展商系统
          </a> -->
          <a
            @click="setActiveTab('exhibitor-services')"
            :class="[
              'nav-item',
              { active: activeTab === 'exhibitor-services' },
            ]"
          >
            展商服务
          </a>
          <a
            @click="setActiveTab('exhibitor-reviews')"
            :class="['nav-item', { active: activeTab === 'exhibitor-reviews' }]"
          >
            展商评语
          </a>
        </nav>
      </div>
    </div>

    <div class="container">
      <section class="content-section">
        <!-- <h2 class="section-title">展商服务</h2>
        <p v-if="pageData.description" class="section-desc">
          {{ pageData.description }}
        </p> -->

        <!-- 多条数据展示：图片在上，文本在下 -->
        <div class="services-grid">
          <div
            class="service-item"
            v-for="service in exhibitorServices"
            :key="service.id"
          >
            <!-- 图片在上 -->
            <div class="service-image-section" v-if="service.image">
              <img
                :src="service.image"
                :alt="service.title"
                class="service-image"
              />
            </div>
            <!-- 文本在下 -->
            <div class="service-content">
              <h3 class="service-title">{{ service.title }}</h3>
              <div
                v-html="service.description"
                class="service-description"
              ></div>
            </div>
          </div>
        </div>
      </section>
    </div>
  </div>
</template>

<script>
import { ref, onMounted } from "vue";
import { subpageApi } from "@/api/user";

export default {
  name: "ExhibitorServices",
  setup() {
    const activeTab = ref("exhibitor-services");
    const bannerImage = ref("");
    // 页面基本信息
    const pageData = ref({});

    // 展商服务数据
    const exhibitorServices = ref([]);

    // 解析富文本内容
    const parseContent = (content) => {
      if (!content) return { content: "", backgroundImage: "" };

      try {
        if (typeof content === "string" && content.trim().startsWith("{")) {
          return JSON.parse(content);
        }
        return { content: content, backgroundImage: "" };
      } catch (e) {
        return { content: content, backgroundImage: "" };
      }
    };

    // 加载展商服务数据
    const loadExhibitorServices = async () => {
      try {
        const response = await subpageApi.getSubpageList(
          "exhibitors",
          "service"
        );
        if (
          response &&
          response.code === "200" &&
          response.data &&
          response.data.length > 0
        ) {
          // 取第一条作为页面基本信息
          const firstItem = response.data[0];
          pageData.value = {
            title: firstItem.title || "展商服务",
            description:
              firstItem.description ||
              (firstItem.content &&
              !(firstItem.content || "").trim().startsWith("[") &&
              !(firstItem.content || "").trim().startsWith("{")
                ? firstItem.content
                : ""),
          };

          // 处理多条展商服务数据
          exhibitorServices.value = response.data.map((item, index) => {
            const parsed = parseContent(item.content);
            return {
              id: item.id || index + 1,
              title: item.title || "",
              description: parsed.content || "",
              image: item.imageUrl || parsed.backgroundImage || "",
            };
          });
        } else {
          // 使用默认数据
          pageData.value = getDefaultPageData();
          exhibitorServices.value = getDefaultExhibitorServices();
        }
      } catch (error) {
        console.error("加载展商服务数据失败:", error);
        pageData.value = getDefaultPageData();
        exhibitorServices.value = getDefaultExhibitorServices();
      }
    };

    const loadBanner = async () => {
      try {
        const res = await subpageApi.getContentByType("carousel_exhibitors");
        if (
          res &&
          (res.code === "200" || res.code === 200) &&
          Array.isArray(res.data) &&
          res.data.length > 0
        ) {
          const firstActive =
            res.data.find((item) => item.status === "active") || res.data[0];
          bannerImage.value = firstActive.imageUrl || firstActive.image || "";
        }
      } catch (e) {
        bannerImage.value = "";
      }
    };

    onMounted(() => {
      loadExhibitorServices();
      loadBanner();
    });

    // 默认页面数据
    const getDefaultPageData = () => {
      return {
        title: "展商服务",
        description: "为参展商提供全方位的服务支持，确保参展体验",
      };
    };

    // 默认展商服务数据
    const getDefaultExhibitorServices = () => {
      return [
        {
          id: 1,
          title: "展位搭建服务",
          description:
            "<p>提供专业的展位搭建服务，包括设计、施工、装饰等一站式解决方案。</p><p>确保展位效果最佳，提升企业形象。</p>",
          image:
            "https://images.unsplash.com/photo-1581091226825-a6a2a5aee158?w=400&h=300&fit=crop",
        },
        {
          id: 2,
          title: "物流运输服务",
          description:
            "<p>提供展品运输、仓储、配送等物流服务，确保展品安全准时到达。</p><p>专业的物流团队，让您无后顾之忧。</p>",
          image:
            "https://images.unsplash.com/photo-1551288049-bebda4e38f71?w=400&h=300&fit=crop",
        },
        {
          id: 3,
          title: "现场技术支持",
          description:
            "<p>提供现场技术支持服务，包括设备调试、网络配置、技术咨询等。</p><p>专业技术团队，确保展会顺利进行。</p>",
          image:
            "https://images.unsplash.com/photo-1565043589221-1a6fd9a6d0b8?w=400&h=300&fit=crop",
        },
        {
          id: 4,
          title: "商务对接服务",
          description:
            "<p>提供商务对接服务，帮助参展商与潜在客户建立联系。</p><p>专业的商务团队，促进合作机会。</p>",
          image:
            "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=400&h=300&fit=crop",
        },
      ];
    };

    const setActiveTab = (tabKey) => {
      if (!tabKey) return;
      activeTab.value = tabKey;
      // 跳转到对应的子页面
      if (tabKey !== "exhibitor-services") {
        window.location.href = `/${tabKey}`;
      }
    };

    return {
      activeTab,
      bannerImage,
      pageData,
      exhibitorServices,
      setActiveTab,
    };
  },
};
</script>

<style scoped>
.exhibitor-services {
  min-height: 100vh;
  background: #f8f9fa;
}

.page-header {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  padding: 120px 0 80px 0;
  margin-top: 0;
  text-align: center;
  color: white;
}

.page-header.has-bg {
  height: 400px;
  position: relative;
  background: none;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.page-header.has-bg::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.page-header.has-bg .container {
  position: relative;
  z-index: 1;
}

.page-title {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 1rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.page-subtitle {
  font-size: 1.2rem;
  opacity: 0.9;
  margin-bottom: 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.content-section {
  background: white;
  border-radius: 20px;
  padding: 3rem;
  margin: 2rem 0;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.section-title {
  font-size: 2rem;
  color: #333;
  margin-bottom: 2rem;
  text-align: center;
  position: relative;
  padding-left: 15px;
}

.section-title::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 2px;
}

.section-desc {
  margin: -8px 0 2rem;
  color: #666;
  text-align: center;
  font-size: 1.1rem;
  line-height: 1.6;
}

/* 多条数据纵向布局 */
.services-grid {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  /* margin-top: 2rem; */
}

.service-item {
  background: white;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.service-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15);
}

/* 图片在上 */
.service-image-section {
  width: 100%;
  padding-bottom: 60%;
  /* height: 300px; */
  position: relative;
  overflow: hidden;
}

.service-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.service-item:hover .service-image {
  transform: scale(1.05);
}

/* 文本在下 */
.service-content {
  padding: 2rem;
}

.service-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: #333;
  margin-bottom: 1rem;
  text-align: center;
}

.service-description {
  color: #666;
  line-height: 1.6;
  text-align: left;
}

/* 富文本内图片限制 */
.service-description :deep(img) {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 10px 0;
  border-radius: 8px;
}
:deep(.resizable-image) {
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
}
@media (max-width: 768px) {
  .page-title {
    font-size: 2rem;
  }

  .content-section {
    padding: 2rem;
    margin: 1rem 0;
  }

  .section-title {
    font-size: 1.5rem;
  }

  .services-grid {
    gap: 1.5rem;
  }
}

/* 导航菜单样式 - 参考关于我们页面 */
.nav-menu {
  background: #f8f9fa;
  padding: 20px 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.about-nav {
  display: flex;
  justify-content: center;
  gap: 30px;
  flex-wrap: wrap;
}

.nav-item {
  text-decoration: none;
  color: #333;
  font-size: 1.1rem;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 8px;
  transition: background-color 0.3s ease, color 0.3s ease;
  border: 1px solid #eee;
  cursor: pointer;
}

.nav-item:hover {
  background-color: var(--e-global-color-selected);
  color: white;
  border-color: var(--e-global-color-selected);
}

.nav-item.active {
  background-color: var(--e-global-color-selected);
  color: white;
  border-color: var(--e-global-color-selected);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .about-nav {
    gap: 15px;
  }

  .nav-item {
    font-size: 1rem;
    padding: 8px 16px;
  }
}
</style>
